//
//  YYNavigationController.swift
//  YYWeibo
//
//  Created by strongwallyi on 15/12/28.
//  Copyright © 2015年 strongwallyi. All rights reserved.
//

import UIKit

class YYNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    //控制器的跳转
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        print(viewController)
        
        if childViewControllers.count > 0 {
        
            var backTitle = "返回"
            
            if childViewControllers.count == 1{
            
                backTitle = childViewControllers.first?.title ?? "返回"
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            
            //跳转到子控制器的时候隐藏底部的toolbar
            viewController.hidesBottomBarWhenPushed = true
        }
        //执行完这句代码,才代表push 执行完成
        super.pushViewController(viewController, animated: animated)
    }

    @objc private func back(){
        popViewControllerAnimated(true)
    }



}
